import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import {
  Router,
  NavigationEnd,
  RouteConfigLoadStart,
  NavigationError,
  ActivatedRoute,
} from '@angular/router';
import { Title } from '@angular/platform-browser';  


@Component({
  selector: 'app-pages',
  templateUrl: './pages.component.html',
  styleUrls: ['./pages.component.css']
})
export class PagesComponent implements OnInit {
  isCollapsed = false;//菜单收起控制
  menus = [];//菜单数组
  config;
  // 当前登录的用户名
  userName = '';
  contentHeight: Number;
  triggerTemplate = null;
  @ViewChild('trigger') customTrigger: TemplateRef<void>;


  constructor(
    private router: Router, 
    private activatedRoute: ActivatedRoute,
    private titleService: Title
  ) { }

  ngOnInit() {
    // this.getUserMessage();
    this.contentHeight = document.body.clientHeight - 64;
    this.router.events
            .subscribe((event) => {this.titleService.setTitle(event['title'])});
        this.config = this.activatedRoute.snapshot.data;
        this.titleService.setTitle(this.config.title);
  }
  /** custom trigger can be TemplateRef **/
  changeTrigger(): void {
    this.triggerTemplate = this.customTrigger;
  }
  logout(): void {
    sessionStorage.removeItem('token');
    this.router.navigate(['login']);
  }

  // 获取登录名
  getUserMessage(): void {
    const params = {
      method: 'get',
      url: 'getUser',
      message: {
        success: '',
        error: '',
        type: 0
      },
    };
    
  }
  setStyle() {
    return {
      padding: '24px;',
      minHeight: this.contentHeight + 'px'
    };
  }
}
